package com.browser.devtools;

import javafx.application.Platform;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;

public class NetworkPanel {
    private final BorderPane content;
    private final TableView<NetworkRequest> requestTable;

    public NetworkPanel() {
        this.content = new BorderPane();
        this.requestTable = new TableView<>();
        
        initializeUI();
    }

    private void initializeUI() {
        TableColumn<NetworkRequest, String> urlCol = new TableColumn<>("URL");
        urlCol.setCellValueFactory(new PropertyValueFactory<>("url"));
        
        TableColumn<NetworkRequest, String> methodCol = new TableColumn<>("Method");
        methodCol.setCellValueFactory(new PropertyValueFactory<>("method"));
        
        TableColumn<NetworkRequest, Integer> statusCol = new TableColumn<>("Status");
        statusCol.setCellValueFactory(new PropertyValueFactory<>("status"));
        
        requestTable.getColumns().addAll(urlCol, methodCol, statusCol);
        content.setCenter(requestTable);
    }

    public void addRequest(String url, String method, int status) {
        Platform.runLater(() -> 
            requestTable.getItems().add(new NetworkRequest(url, method, status))
        );
    }

    public BorderPane getContent() {
        return content;
    }

    public static class NetworkRequest {
        private final String url;
        private final String method;
        private final int status;

        public NetworkRequest(String url, String method, int status) {
            this.url = url;
            this.method = method;
            this.status = status;
        }

        public String getUrl() { return url; }
        public String getMethod() { return method; }
        public int getStatus() { return status; }
    }
} 